package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.GoodsBean;
import com.project.bean.GoodsTotalBean;
import com.project.bean.ShowGoodsBean;
import com.project.mapper.IGoodsMapper;
import com.project.mapper.IGoodsTotalMapper;
import com.project.mapper.IShowGoodsMapper;
import com.project.service.IShowGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class ShowGoodsServiceImpl implements IShowGoodsService {
    @Autowired
    private IShowGoodsMapper showGoodsMapper;
    @Autowired
    private IGoodsTotalMapper goodsTotalMapper;
    @Override
    public ShowGoodsBean findById(Integer showGoodsId) {
        return showGoodsMapper.selectById(showGoodsId);
    }

    @Override
    public void add(Integer goodsId, double salePrice, String picturePath, Integer esId, String text) {
        GoodsTotalBean goodsTotalBean = goodsTotalMapper.selectById(goodsId);

//        ShowGoodsBean showGoodsBean = new ShowGoodsBean(goodsBean.getName(), goodsBean.getSize(),
//                goodsBean.getColor(), goodsBean.getCreateAddress(),goodsBean.getCreateDate(),
//                salePrice,picturePath,esId,text,goodsBean.getType(), goodsBean.getNum());

        ShowGoodsBean showGoodsBean = new ShowGoodsBean(goodsId,goodsTotalBean.getName(), goodsTotalBean.getSize(),
                goodsTotalBean.getColor(),salePrice,picturePath,esId,text,goodsTotalBean.getType(),goodsTotalBean.getNum());
        showGoodsMapper.insert(showGoodsBean);

    }

    @Override
    public void updateStatus(Integer showGoodsId, String newStatus) {
        ShowGoodsBean showGoodsBean = showGoodsMapper.selectById(showGoodsId);
        showGoodsBean.setStatus(newStatus);
        showGoodsMapper.updateById(showGoodsBean);
    }

    @Override
    public Page<ShowGoodsBean> cutFindByItem(Integer pageNum, String status) {
        QueryWrapper<ShowGoodsBean> qw = new QueryWrapper<>();
        if (status != null && !status.equals("")){
            qw.eq("sg_status",status);
        }
        return showGoodsMapper.selectPage(new Page<>(pageNum,3),qw);
    }
}
